#include "widget.h"
#include <QApplication>

#include <QPushButton>
#include <QLCDNumber>
#include <QRadioButton>
#include <QVBoxLayout>
#include <QGroupBox>
#include <QButtonGroup>
#include <QObject>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    QWidget *w_control = new QWidget;

    QPushButton *btn_closdlist  = new QPushButton("扩展节点数");
    QLCDNumber *lcd_closdlist = new QLCDNumber;

    QPushButton *btn_run_time  = new QPushButton("运行时间(s)");
    QLCDNumber *lcd_run_time = new QLCDNumber;

// 算法
    QGroupBox *groupBox_algorithm = new QGroupBox("算法");
    QButtonGroup *botton_group_algorithm = new QButtonGroup;

    QRadioButton *radio_astar = new QRadioButton("A Star");
    QRadioButton *radio_dijkstra = new QRadioButton("Dijkstra");
    QRadioButton *radio_greedy = new QRadioButton("Greedy");

    botton_group_algorithm->addButton(radio_astar,0);
    botton_group_algorithm->addButton(radio_dijkstra,1);
    botton_group_algorithm->addButton(radio_greedy,2);

    radio_astar->setChecked(true);

    QVBoxLayout *vbox = new QVBoxLayout;

    vbox->addWidget(radio_astar);
    vbox->addWidget(radio_greedy);
    vbox->addWidget(radio_dijkstra);

    vbox->addStretch(1);

    groupBox_algorithm->setLayout(vbox);

// 画笔
    QGroupBox *groupBox_pen = new QGroupBox("画笔");
    QButtonGroup *botton_group_pen = new QButtonGroup;

    QRadioButton *radio_start_end = new QRadioButton("起终点");
    QRadioButton *radio_obstruct = new QRadioButton("设置障碍");
    QRadioButton *radio_eraser = new QRadioButton("擦除障碍");

    botton_group_pen->addButton(radio_start_end,0);
    botton_group_pen->addButton(radio_obstruct,1);
    botton_group_pen->addButton(radio_eraser,2);

    radio_start_end->setChecked(true);

    QVBoxLayout *vbox_pen = new QVBoxLayout;

    vbox_pen->addWidget(radio_start_end,0);
    vbox_pen->addWidget(radio_obstruct,1);
    vbox_pen->addWidget(radio_eraser,2);

    vbox_pen->addStretch(1);

    groupBox_pen->setLayout(vbox_pen);



    QVBoxLayout *layout = new QVBoxLayout;

    lcd_closdlist->setSegmentStyle(QLCDNumber::Flat);
    lcd_closdlist->setStyleSheet("border: 1px solid green; color: black;");
    lcd_closdlist->display("0");

    lcd_run_time->setSegmentStyle(QLCDNumber::Flat);
    lcd_run_time->setStyleSheet("border: 1px solid green; color: black;");
    lcd_run_time->display("0");

    layout->addWidget(btn_closdlist);
    layout->addWidget(lcd_closdlist);
    layout->addWidget(btn_run_time);
    layout->addWidget(lcd_run_time);
    layout->addWidget(groupBox_algorithm);
    layout->addWidget(groupBox_pen);

    w_control->setLayout(layout);

    QObject::connect(&w,SIGNAL(closedlist_value_changed(int)),lcd_closdlist,SLOT(display(int)));
    QObject::connect(&w,SIGNAL(run_time(double)),lcd_run_time,SLOT(display(double)));
    QObject::connect(botton_group_algorithm,SIGNAL(buttonClicked(int)),&w,SLOT(set_algorithm_flag(int)));
    QObject::connect(botton_group_pen,SIGNAL(buttonClicked(int)),&w,SLOT(set_pen_flag(int)));

    w_control->show();

    return a.exec();
}
